package com.six.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.six.pojo.Education;
import com.six.pojo.vo.EducationVo;
import com.six.result.Result;
import com.six.result.ResultUtils;
import com.six.service.EducationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@Slf4j
@RequestMapping("/education")
@Api(tags = "y教育情况")
@CrossOrigin
@ResponseBody
public class EducationController {

    @Autowired
    private EducationService educationService;


    @PostMapping("/list")
    @ApiOperation(value = "查询教育情况")
    public Result list(EducationVo educationVo){

        LambdaQueryWrapper<Education> wrapper = new LambdaQueryWrapper();
        wrapper.eq(Education::getAdminId,educationVo.getAdminId());
        //分页条件
        Page page = new Page(educationVo.getPage(),educationVo.getLimit());

        Page page1 = educationService.page(page, wrapper);

        return ResultUtils.buildSuccess(page1.getTotal(),page1.getRecords());
    }


    @PostMapping("/add")
    @ApiOperation(value = "增加教育情况")
    public Result add(@RequestBody Education education){
        education.setStartTime(new Date());
        educationService.save(education);
        return ResultUtils.buildSuccess();
    }

    @PutMapping("/update")
    @ApiOperation("根据id修改")
    public Result update(@RequestBody Education education){
        educationService.updateById(education);
        return ResultUtils.buildSuccess();
    }


    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据id删除")
    public Result delete(@PathVariable("id") Long id){
        educationService.removeById(id);
        return ResultUtils.buildSuccess();
    }
}
